#include<stdio.h>
#include "../include/vfs.h"
#include<stdlib.h>
#include<string.h>


int movedir(char source[], char destin[])
{

	FD *dest,*src,*src_exist,*dest_exist,*src_exist1=NULL,*dest_exist1=NULL;
	source_exist=0;

	if(strstr(destin,source)!=NULL)
		return 6;

	dest = malloc(sizeof(FD));
	src = malloc(sizeof(FD));

	dest_exist = malloc(sizeof(FD));
	src_exist = malloc(sizeof(FD));

	if(source[strlen(source)-1]=='/')
	{
		source[strlen(source)-1]='\0';

	}	

	if(destin[strlen(destin)-1]=='/' && strlen(destin)>2)
	{

		destin[strlen(destin)-1]='\0';
	}



	strcpy(dest->path,destin);
	strcpy(src->path,source);

	

		src_exist1 = search(roots.naryroot,src);
		dest_exist1 = search(roots.naryroot,dest);
		
		if(src_exist1==NULL)
			return 1;

		if(dest_exist1==NULL)
			return 2;

		if(dest_exist1->file_type>0)
			return 7;

		if(strcmp(source,"")==0)
			return 3;

		if(strcmp(destin,"")==0)
			return 4;
	

		//printf("\n MOVE DIR");

		roots.naryroot = movedirectory(roots.naryroot,dest,src);
		delete_bst(src->path,roots.bstRoot);

		if(source_exist==1)
			return 5;

		hash_deletion(src);

	return 0;
}
